<?php

class Content extends Controller
{
    private $default_row_index = 10;
    private $default_table = 'classe';
    
    function Content()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('email');
        $this->load->model('ignitedrecord/ignitedrecord');
        $this->load->library('table');
        $this->load->library('pagination');
    }
    
    function index()
    {
        $this->show($this->default_table, $this->default_row_index);
    }    
    
    function show($table, $index = 10)
    {
        $this->load->model($table);
        $this->load->view('admin_view_content', array('table' => $table, 'index' => $index));
    }
    
    function remove($table, $id)
    {
        $this->load->model($table);
        $deleted = $this->$table->find($id);
        $deleted->delete();
        $this->show($table); 
    }
    
    function change_page()
    {
        $index = $_POST['row_index'] + $_POST['shift'];
        $this->show($_POST['table'], $index);
    }
        
    function select($what)
    {
        $multi = 0;
        $opt = '';
        
        if (count($tmp = explode("_", $what)) > 1):
            $what = $tmp[0];
            $opt = $tmp[1];
        endif;
        
        $this->load->model($what);
        
        $result = $this->$what->get();
        $query = $result['query'];
        $heading = $result['heading'];

        switch($what):
            case 'student':
                $multi = 1;
                break;
            case 'classe':
                if ($opt == 'master'):
                    $result = $this->$what->get_no_master();
                    $query = $result['query'];
                    $count = $result['count'];
                elseif ($opt == 'subjects'):
                    $multi = 1;
                endif;
                
                break;
        endswitch;
        
        $heading[] = "Wybierz";

        $this->load->view('admin_view_select', array('multi' => $multi, 'heading' => $heading, 'query' => $query));
    }
}

?>
